﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using System.Text;


namespace AI
{
    public class MathUtil
    {

        // 목적지 살짝옆으로
        public static System.Windows.Vector GetNextPos(float sx, float sy, float dx, float dy)
        {
            Vector3 dir = Vector3.Normalize(new Vector3(dx - sx, dy - sy,0));
            Matrix mat = Matrix.CreateRotationZ(90 * (float)Math.PI / 180);
            dir = Vector3.Transform(dir, mat);
            dir *= 0.000015f;
            return new System.Windows.Vector(dx + dir.X, dy + dir.Y);
        }

        public static float GetDegreesForBaseRotation(float diffX, float diffZ)
        {
            Vector3 newBinormalVector = new Vector3(0, 0, 1);
            Vector3 newtargetPos = new Vector3(diffX, 0, diffZ);

            float rovAngul = (float)GetRadianFromTwoVectors(newBinormalVector, newtargetPos);

            if (diffX >= 0)
                return RadiansToDegrees(rovAngul);
            else
                return -RadiansToDegrees(rovAngul);
        }

        public static double GetRadianFromTwoVectors(Vector3 v1, Vector3 v2)
        {
            
            double ang = Math.Acos(Vector3.Dot(v1, v2) / (v1.Length() * v2.Length()));

            return ang;
        }

        public static double GetRadianFromPos(Vector2 pos1, Vector2 pos2)
        {
            double x = pos2.X - pos1.X;
            double y = pos2.Y - pos1.Y;

            double ang = Math.Atan(y / x);

            return ang;
        }

        public static float GetDotDegreeFromLengths(float a, float b, float c)
        {
            float ang_A = (float)Math.Acos((b * b + c * c - a * a) / (2 * b * c));

            ang_A = ang_A * 360 / (2 * (float)Math.PI);

            return ang_A;
        }

        public static float DegreesToRadians(float deg)
        {
            return (float)(deg * Math.PI / 180.0f);
        }

        public static float RadiansToDegrees(float rad)
        {
            return (float)(rad * 180.0f / Math.PI);
        }

    }
}
